﻿using CPPEI.Coolzon.Common;
using CPPEI.Coolzon.Service.Contract;
using CPPEI.Coolzon.UI.Views.Events;
using Sunboxsoft.ChanceData.ServiceProxy.MainServiceRef;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CPPEI.Coolzon.UI.Views.EventProxies
{
    public class SwitchMainServerHandler : BaseResponseHandler<RespSwitchMainServerData>
    {
        protected override void OnHandle(RemoteEventProxy remoteEventProxy, Response response, 
            RespSwitchMainServerData responseData)
        {
            if(responseData.IsSuccess && string.Equals(responseData.ServerIP, responseData.MainServerIP) && responseData.MainServerPort == responseData.Port)
            {
                UIContext.Current.UpdateMainServer(responseData.ServerIP, responseData.Port);
                UIContext.Current.UpdateMainServer4Switching(null);
                Logger.DebugToTag(Library.LogTag, "收到{0}:{1}指令切换主服务器，切换为主服务器为{2}:{3}", responseData.ServerIP, responseData.Port,UIContext.Current.MainServerIP, UIContext.Current.MainServerPort);
            }
            else
            {
                Logger.DebugToTag(Library.LogTag, "收到{0}:{1}指令切换主服务器，切换为主服务器为{2}:{3},Message:{4},当前主服务{5}:{6}", responseData.ServerIP, responseData.Port, responseData.MainServerIP, responseData.MainServerPort, responseData.Message, UIContext.Current.MainServerIP, UIContext.Current.MainServerPort);
            }
        }
    }
}
